<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="iwpl.project.entities.*"%>
<%@page import="iwpl.project.servlet.*"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="iwpl.project.dao.EmployeesDAO"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
//String t = (String)session.getAttribute("Manage_Employee");
//if(t!="active")
	//{response.sendRedirect("index.jsp");}
 %>
<html>
	<head>
		<link rel="stylesheet" href="css/CommonCSS.css" type="text/css"></link>
		<meta http-equiv="Content-Type"
			content="text/html; charset=UTF-8">
		<title>Manage Employee</title>
	</head>
	<body>

		<div>
			<div style="margin: 0 auto; margin-top: 2px; margin-bottom: 0px">
			<form action="" method="post">
				<table style="margin: 0 auto; width: auto">
					<tr>
						<td> 
							<br>Filter by name: 
						</td>
						<td>
							<input type="text" name="empName" />
						</td>

						<td>
							<button type="submit" style="width: 120px; height: 25px">
								Filter
							</button>
						</td>
					</tr>
					<tr>
						<td>
							<a class="link" href="/DepartmentManage/Insert_Employee.jsp">Create
								new</a>
						</td>
					</tr>
				</table>
				</form>
			</div>
			<table
				style="border: 1px; border-color: black; min-width: 400px; margin: 0px auto">
				<tr>
					<td style="background-color: #006699;">
						Full name
					</td>
					<td style="background-color: #006699;">
						Phone
					</td>					
					<td style="background-color: #006699;">
						Birth Date
					</td>
					<td style="background-color: #006699;">
						Address
					</td>
					<td style="background-color: #006699;">
						Office
					</td>
					<td style="background-color: #006699;">
						Edit
					</td>
					<td style="background-color: #006699;">
						Delete
					</td>
				</tr>
				<%
				EmployeesDAO dao = new EmployeesDAO();
				
				List<Employees> list = null;
				if(request.getParameter("empName") != null) {
					list = dao.findByName(request.getParameter("empName"));
				} else {
					list = dao.findAll();
				}	
				for(Iterator<Employees> i = list.iterator(); i.hasNext(); ) {
					Employees emp = (Employees)i.next();	
				%>
				<tr>
					<td><%=emp.getFullName() %></td>
					<td><%=emp.getPhone() %></td>					
					<td><%=emp.getBirthday() %></td>
					<td><%=emp.getAddress() %></td>
					<td><%=emp.getOffices().getOfficeName() %></td>
					<td>
						<a class="link"
							href="/DepartmentManage/Update_Employee.jsp?id=<%=emp.getId()%>">Edit</a>
					</td>
					<td>
						<a class="link" href="javascript:doDelete(<%=emp.getId()%>)">Delete</a>
					</td>
				</tr>
				<% 	} %>
			</table>
			<script type="text/javascript">
	function doDelete(id)
	{
		input_box=confirm("Bạn có thực sự muốn xóa mẫu tin này không?");
		if (input_box==true) {
		  document.location.href ="./servlet/EMPLOYEE_Servlet?action=delete&id="+id;
		}	
	}
</script>
		</div>
	
	</body>
</html>